import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { TilePanel } from "../../equipment/TilePanel";
import { GuildCallerRenderer } from "./GuildCallerRenderer";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { SGuildCallTogether } from "../../../../../Message/Game/SGuildCallTogether";
import { DataEvent } from "../../../events/DataEvent";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { CheckBox } from "../../../../../fl/controls/CheckBox";
type int = number;
//class GuildCallTogetherWindow
    
    export  class GuildCallTogetherWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._getherInfos = [];
            this.setSize(400, 245);
            this.titleHeight = 26;
            this.title = ObjCreate.createTitleTextField(Language.getString(60751));
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(15, 34, 374, 172, this);
            this._minimizeBtn = ObjCreate.createGButton("", 352, 8, 19, 19, this, "MinimizeButton");
            this._minimizeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this._callerList = new TilePanel();
            this._callerList.horizontalGap = 3;
            this._callerList.verticalGap = 3;
            this._callerList.columnWidth = 356;
            this._callerList.rowHeight = 40;
            this._callerList.setSize(356, 166);
            this._callerList.move(30, 40);
            this._callerList.setStyle("cellRenderer", GuildCallerRenderer);
            this.addChild(this._callerList);
            this._callerList.addEventListener(GModuleEvent.Guild_CallTogetherFly, this.onAutoFly);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.x = 160;
            this._pageSelecter.y = 215;
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            this.addChild(this._pageSelecter);
            this._delayBtn = ObjCreate.createGButton(Language.getString(60755), 285, 210, 100, 26, this, "ButtonLarge");
            this._delayBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.currentTarget;
            switch (loc1) 
            {
                case this._minimizeBtn: case this._delayBtn:
                {
                    this.dispatchEvent(new Object /* flash.events.Event */(GuildCallTogetherWindow.DoMinimize, false, true));
                    this.hide();
                    break;
                }
            }
            return;
        }

        public addGatherInfo(arg1: SGuildCallTogether): void
        {
            this._getherInfos.push(arg1);
            this.updateDataProvider();
            return;
        }

        public deleteInfo(arg1: SGuildCallTogether): void
        {
            var loc1=this._getherInfos.indexOf(arg1);
            if (loc1 != -1) 
            {
                this._getherInfos.splice(loc1, 1);
            }
            this.updateDataProvider();
            return;
        }

        /* internal  */updateDataProvider(): void
        {
            this._pageSelecter.maxPage = Math.ceil(this._getherInfos.length / this.pageSize);
            this._callerList.dataProvider = this.getDataProvider();
            this._callerList.drawNow();
            if (this._getherInfos.length == 0) 
            {
                this.hide();
            }
            return;
        }

        /* internal  */onAutoFly(arg1: DataEvent): void
        {
            var e: DataEvent;
            var info: SGuildCallTogether;

            var loc1;
            info = null;
            e = arg1;
            info = e.data as SGuildCallTogether;
            with ({}) 
            {
            };
            info.fromPos.map.convey(info.fromPos.x, info.fromPos.y, 
#error('pushwith') {}
            , 
#error('pushwith') {}
            .success = (arg1): void
            {
                deleteInfo(info);
                return;
            })
            return;
        }

        protected /* override */ closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.closeBtnClickHandler(arg1);
            this._getherInfos = new Array<any>();
            this.updateDataProvider();
            return;
        }

        /* internal  */getDataProvider(): DataProvider
        {
            var loc1=new Array<any>();
            var loc2=(this._pageSelecter.currentPage - 1) * this.pageSize;
            var loc3=Math.min(this._pageSelecter.currentPage * this.pageSize, this._getherInfos.length);
            var loc4=loc2;
            while (loc4 < loc3) 
            {
                loc1.push(this._getherInfos[loc4]);
                ++loc4;
            }
            return new DataProvider(loc1);
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */): void
        {
            this._callerList.dataProvider = this.getDataProvider();
            this._callerList.drawNow();
            return;
        }

        /* internal */ /* const */pageSize: int=4;

        public static /* const */DoMinimize: string="面板最小化";

        /* internal */ /* var */_minimizeBtn: GButton;

        /* internal */ /* var */_callerList: TilePanel;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_checkBoxToday: CheckBox;

        /* internal */ /* var */_delayBtn: GButton;

        /* internal */ /* var */_getherInfos: Array<any>;
    }
